<?php
namespace app\api\controller;
use think\facade\Db;
class Loadimg extends Base{
	function index(){
		$list = Db::name('channel_server')
				->where('tmp_img','exp', 'is null')
				->where('channel_id','exp','<>4')
				->order('id asc')
				->select();
		foreach($list as $k=>$v){
			if($v['server_ico']){
				$rs = @file_get_contents($v['server_ico']);
				$fileDir = public_path().'upload/server/';

				//按小时拆分
			    if(!is_dir($fileDir)){
			        mk_dir($fileDir);
			    }

			    $url = $fileDir."server_".$v['id'].".png";
			    file_put_contents($url, $rs);

			    $tmp_img = "/upload/server/server_".$v['id'].".png";

			    Db::name('channel_server')
			    ->where('id', $v['id'])
			    ->update(['tmp_img'=>$tmp_img]);
			}
		}
		echo "OK";
		// exit;
	}
	function country(){
		$list = Db::name('channel_country')
				->where('tmp_img','exp', 'is null')
				->where('channel_id','exp','<>4')
				->order('id asc')
				->select();
		foreach($list as $k=>$v){
			if($v['country_ico']){
				$rs = file_get_contents($v['country_ico']);
				$fileDir = public_path().'upload/country/';

				//按小时拆分
			    if(!is_dir($fileDir)){
			        mk_dir($fileDir);
			    }

			    $url = $fileDir."country_".$v['id'].".png";
			    file_put_contents($url, $rs);

			    $tmp_img = "/upload/country/country_".$v['id'].".png";

			    Db::name('channel_country')
			    ->where('id', $v['id'])
			    ->update(['tmp_img'=>$tmp_img]);
			}
		}
		echo "OK";
		// exit;
	}
}